package internal

import (
	"fmt"
	"strings"
)

type (
	Namespace string
	TaskID    string
)

const (
	namespacePrefix = "v8s-"
)

func (id TaskID) ToNamespace() (Namespace, error) {
	if id == "" {
		return "", fmt.Errorf("empty task id")
	}

	return Namespace(namespacePrefix + id), nil
}

func (name Namespace) ToTaskID() (TaskID, error) {
	if name.IsTask() {
		return TaskID(strings.TrimPrefix(string(name), namespacePrefix)), nil
	}

	return "", fmt.Errorf("namespace '%s' does not belong to drop-app", name)
}

func (name Namespace) IsTask() bool {
	return strings.HasPrefix(string(name), namespacePrefix)
}
